<?php
/**
* phpCan - http://idc.anavallasuiza.com/
*
* phpCan is released under the GNU Affero GPL version 3
*
* More information at license.txt
*/

namespace data\formats;

defined('ANS') or die();

class Image extends File implements iFormats {
	var $format = 'image';

	public function check ($value) {
		$this->error = array();

		if (!$this->checkFile($value[''])) {
			return false;
		}

		return true;
	}

	public function valueDB (\data\Data $Data, $value, $language = '', $id = 0) {
		$result = $this->saveFile($value[''], $id);

		if (is_array($result) || $result === false) {
			return $result;
		}

		$settings = $this->settings[''];

		//Transform image
		if ($settings['transform']) {
			$image = getImageObject();

			$ok = $image->load($settings['base_path'].$settings['uploads'].$settings['subfolder'].$result)->transform($settings['transform'])->save();

			if (!$ok) {
				return false;
			}
		}

		return array('' => $settings['subfolder'].$result);
	}

	public function settings ($settings) {
		parent::settings($settings);

		$this->settings['']['default'] = $settings['default'];
		$this->settings['']['transform'] = $settings['transform'];
		
		$this->settings['']['mime_types'] = array(
			'image/png',
			'image/jpeg',
			'image/gif',
		);

		return $this->settings;
	}
}
?>
